import os
import sys
import argparse
import logging
import concurrent.futures
import asyncio

from  agent.qwen.BaiLianTextAgent import BaiLianTextAgent

# 日志
logger = logging.getLogger(__name__)

# 服务配置
api_key = "sk-bbeb8854532e44ac8e1c21246b181964"
base_url = "https://dashscope.aliyuncs.com/compatible-mode/v1"
model = "deepseek-v3.1"
api_type = "openai"
stream_out = True
thinking = True


# AI Agent 主程序
class AIAgentMain:
    def __init__(self):
        self.agent = BaiLianTextAgent(api_key=api_key, base_url=base_url, model=model, api_type=api_type,
                                 stream_out=stream_out,
                                 thinking=thinking, multi_chat=True)
    async def init_async(self):
        await self.agent.start_text_chat()


# 配置logging
def config_logging(env, log_path, app_name):
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    # 生产环境
    if env == "test" or env == "uat" or env == "prod":
        file_path = log_path + os.path.sep + app_name
        if not os.path.exists(file_path):
            os.makedirs(file_path)
        # INFO信息日志
        info_handler = logging.FileHandler(file_path + os.path.sep + app_name + "_info.log")
        info_handler.setLevel(logging.INFO)
        info_handler.setFormatter(formatter)
        # Error日志
        error_handler = logging.FileHandler(file_path + os.path.sep + app_name + "_error.log")
        error_handler.setLevel(logging.ERROR)
        error_handler.setFormatter(formatter)
        logging.basicConfig(level=logging.INFO, handlers=[info_handler, error_handler])
    else:
        # 创建file handler并设置级别、formatter
        logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", datefmt='%Y-%m-%d %H:%M:%S')

def main():
    config_logging("dev", "d:\\pylog", "ai_agent")
    logger.info("启动文本对话")
    asyncio.run(AIAgentMain().init_async())
    logger.info("文本对话启动成功")

if __name__ == '__main__':
    main()
    while True:
        pass






